package com.bins.charts.controller;

import com.alibaba.fastjson.JSON;
import com.bins.charts.service.EChartService;
import com.bins.charts.vo.FertilizerAndGrainChartVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class EChartController {

    @Autowired
    private EChartService eChartService;

    @RequestMapping(value = "/first", method = RequestMethod.GET)
    public ModelAndView firstDemo() {
        return new ModelAndView("test");
    }

    @RequestMapping(value = "/basicLineChart", method = RequestMethod.GET)
    public ModelAndView basicLineChart() {
        return new ModelAndView("basicLineChart");
    }

    @RequestMapping(value = "/smoothedLineChart", method = RequestMethod.GET)
    public ModelAndView smoothedLineChart() {
        return new ModelAndView("smoothedLineChart");
    }

    @RequestMapping(value = "/basicAreaChart", method = RequestMethod.GET)
    public ModelAndView basicAreaChart() {
        return new ModelAndView("basicAreaChart");
    }

    @RequestMapping(value = "/stackedLineChart", method = RequestMethod.GET)
    public ModelAndView stackedLineChart() {
        return new ModelAndView("stackedLineChart");
    }

    @RequestMapping(value = "/fertilizerAndGrainChart", method = RequestMethod.GET)
    public ModelAndView fertilizerAndGrainChart() {
        return new ModelAndView("fertilizerAndGrainChart");
    }

    @RequestMapping(value = "/howler", method = RequestMethod.GET)
    public ModelAndView howler() {
        return new ModelAndView("howlerPage");
    }

    @RequestMapping(value = "/dynamicFertilizerAndGrainChart", method = RequestMethod.GET)
    public ModelAndView dynamicFertilizerAndGrainChart() {
        FertilizerAndGrainChartVo chartVo = eChartService.getFertilizerAndGrainChartData();
        ModelAndView mv = new ModelAndView("dynamicFertilizerAndGrainChart");
        mv.getModel().put("data", JSON.toJSONString(chartVo));
        return mv;
    }

}
